#ifndef _LAULL_WIN_PROGRESS_
#define _LAULL_WIN_PROGRESS_

#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif // !_CRT_SECURE_NO_WARNINGS

#ifndef WIN_PROGRESS_USE_OLD_UI
// win现代ui支持，而不是默认调用老ui
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif //!_M_IX86
#endif //!_UNICODE
#endif //!USE_OLD_UI

#include <windows.h>
#include <CommCtrl.h>
#pragma comment(lib, "Comctl32")
#include <stdio.h>
#include <stdlib.h>
#include <thread>
#include <map>
#include <ctime>
#include <string>

namespace LAULL_PROGRESS_WIN {
    struct WIN_item
    {
        HWND hwnd;
        int hmenu;
    };

    static int hight = 400, width = 200;

    struct LaullProgressItems {
        HWND hwnd = NULL;
        struct WIN_item
            button_cancel = { NULL, 1 },
            progress_bar = { NULL, 2 };
        ULONGLONG _total = 100, _init_num = 0;
        TCHAR use_text[1024] = TEXT("");  // 显示文本
        int win_return = 0;               // 将要返回的值
        BOOL ALLOW_CANCEL = 1;
    };

}


class WinProgress {
    bool finish = false, inited = false;
    std::thread t;
    LAULL_PROGRESS_WIN::LaullProgressItems*  item_p = new LAULL_PROGRESS_WIN::LaullProgressItems;
    int RETURN = 0;
public:
    // 显示位置
    int x = NULL, y = NULL;

    // 初始化
    void init(HWND father, LPCTSTR classname, LPCTSTR title, ULONGLONG total, ULONGLONG init_num, BOOL allow_cancel);

    WinProgress(HWND father, LPCTSTR classname, LPCTSTR title, ULONGLONG total, ULONGLONG init_num, BOOL allow_cancel);

    WinProgress(HWND father, LPCTSTR classname, LPCTSTR title, ULONGLONG total, ULONGLONG init_num, BOOL allow_cancel, int position_x, int position_y);

    WinProgress(HWND father, LPCTSTR title, ULONGLONG total, ULONGLONG init_num, BOOL allow_cancel);

    WinProgress(HWND father, LPCTSTR title, ULONGLONG total, ULONGLONG init_num, BOOL allow_cancel, int position_x, int position_y);

    // 立即关闭
    void Close();

    bool IsFinish();

    // 设置进度条上方描述文字
    void SetText(const TCHAR text[]);

    // 获得此时的进度
    ULONGLONG GetProgress();

    // 设置进度
    void SetProgress(ULONGLONG target);

    // 设置总进度
    void SetTotal(ULONGLONG total);

    // 更新进度
    void Addprogress(ULONGLONG add);

    // 取消返回-1, 关闭返回-2, 手动关闭返回1
    int WaitUntilFinish();

    ~WinProgress();

};
#endif // !_LAULL_WIN_PROGRESS_
